home *** CD-ROM | disk | FTP | other *** search
- Path: newsbf02.news.aol.com!not-for-mail
- From: babycox@aol.com (BabyCox)
- Newsgroups: comp.lang.c
- Subject: Re: quick decision: is n a power of 2?
- Date: 19 Jan 1996 17:19:32 -0500
- Organization: America Online, Inc. (1-800-827-6364)
- Sender: root@newsbf02.news.aol.com
- Message-ID: <4dp5dk$t3r@newsbf02.news.aol.com>
- References: <4dorr8$i58@cloner3.netcom.com>
- Reply-To: babycox@aol.com (BabyCox)
- NNTP-Posting-Host: newsbf02.mail.aol.com
-
-
- >#define ISPOW2(x) (((x) & 1) ^ 1)
-
- That will not work, it returns the next lowest MULTIPLE of two, here's
- what I would do:
-
- Boolean IsPowerOfTwo(long x)
- {
- for(short y = 0;y<=31;y++)
- {
- if (x = 1) return true;
- x >>= 1;
- }
- return false;
- }
-